package com.lwc.cfdns.utils;

import com.lwc.cfdns.enums.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * 结果返回
 *
 * @author luwc
 * @title ResultUtils
 * @description
 * @time 2023/4/21 15:59:03
 * @version: 1.0
 */
@AllArgsConstructor(staticName = "of")
@Data
public class ResultUtils {
    private int code = 200;
    private String msg = "success";
    private Object data = null;
    private long timestamp;

    public ResultUtils(long timestamp) {
        this.timestamp = System.currentTimeMillis() / 1000;
    }

    /**
     * 成功
     *
     * @param msg
     * @return ResultUtils
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/17 11:03:12
     */
    public static ResultUtils success(String msg) {
        return ResultUtils.of(ResultCode.SUCCESS.getCode(), msg, null, System.currentTimeMillis() / 1000);
    }

    /**
     * 失败
     *
     * @param msg
     * @param resultCode
     * @return ResultUtils
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/19 10:09:07
     */
    public static ResultUtils error(String msg, ResultCode resultCode) {
        return ResultUtils.of(resultCode.getCode(), msg, null, System.currentTimeMillis() / 1000);
    }
}
